package com.hzf.wxplatform.web.controller.manager.goods;

/**
 * describe: TODO
 * creat_user: 白开水
 * creat_time: 2017/12/2   13:19
 **/

import ch.hsr.geohash.GeoHash;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.wenhao.geohash.GeoSearch;
import com.github.wenhao.geohash.domain.GeoRange;
import com.hzf.api.rpc.api.ApiService;
import com.hzf.common.base.BaseController;
import com.hzf.common.util.ByteUtils;
import com.hzf.common.util.RedisUtil;
import com.hzf.config.dao.model.ConfigRegion;
import com.hzf.config.dao.model.ConfigRegionExample;
import com.hzf.material.dao.model.*;
import com.hzf.ucenter.dao.model.UcenterUser;
import com.hzf.ucenter.dao.model.UcenterUserCity;
import com.hzf.wxplatform.common.WxplatformResult;
import com.hzf.wxplatform.common.WxplatformResultConstant;
import com.hzf.wxplatform.common.utils.UcenterUserUtils;
import com.hzf.wxplatform.web.utils.GpsTest;
import com.spatial4j.core.io.GeohashUtils;
import com.sun.jndi.cosnaming.IiopUrl;
import javafx.scene.paint.Material;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.security.krb5.Config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.util.*;

/**
 * describe: TODO
 * creat_user: 白开水
 * creat_time: 2017/11/27   14:51
 **/
@Controller
@RequestMapping("/materialGoodsIndex")
public class MaterialGoodsIndexController extends BaseController {
    @Autowired
    ApiService apiService;

    @RequestMapping(value = "/cailiao")
    private String index(Model model, HttpServletRequest request) {
        MaterialGoodsTypeBigExample materialGoodsTypeBigExample = new MaterialGoodsTypeBigExample();
        List<MaterialGoodsTypeBig> bigs = apiService.selectByMaterialGoodsTypeBig(materialGoodsTypeBigExample);
        for (MaterialGoodsTypeBig materialGoodsTypeBig : bigs) {
            MaterialGoodsTypeMiddleExample materialGoodsTypeMiddleExample = new MaterialGoodsTypeMiddleExample();
            materialGoodsTypeMiddleExample.createCriteria().andBigIdEqualTo(materialGoodsTypeBig.getBigId());
            List<MaterialGoodsTypeMiddle> typeMiddles = apiService.selectByMaterialGoodsTypeMiddle(materialGoodsTypeMiddleExample);

            for (MaterialGoodsTypeMiddle materialGoodsTypeMiddle : typeMiddles) {
                MaterialGoodsTypeSmallExample materialGoodsTypeSmallExample = new MaterialGoodsTypeSmallExample();
                materialGoodsTypeSmallExample.createCriteria().andMiddleIdEqualTo(materialGoodsTypeMiddle.getMiddleId());
                List<MaterialGoodsTypeSmall> typeSmalls = apiService.selectByMaterialGoodsTypeSmall(materialGoodsTypeSmallExample);
                if (typeSmalls.size() == 0) {
                    MaterialGoodsTypeSmall materialGoodsTypeSmall = new MaterialGoodsTypeSmall();
                    materialGoodsTypeSmall.setSmallName("其他");
                    typeSmalls.add(materialGoodsTypeSmall);
                }
                materialGoodsTypeMiddle.setMaterialGoodsTypeSmallList(typeSmalls);
            }
            materialGoodsTypeBig.setMaterialGoodsTypeMiddleList(typeMiddles);

        }
        model.addAttribute("bigs", bigs);
        return thymeleaf("/YZ/YZ_BD_BenDiCL");

    }
    @RequestMapping(value = "/getGoodsSlas", method = RequestMethod.POST)
    @ResponseBody

    private Object getGoodsSlas(Model model, HttpServletRequest request, int id, double lat, double lng,@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                            @RequestParam(required = false, defaultValue = "4", value = "limit") int limit,
                            @RequestParam(required = false, value = "sort") String sort,
                            @RequestParam(required = false, value = "order") String order) {
        HttpSession session = request.getSession();
        UcenterUser ucenterUser = new UcenterUser();
        ConfigRegion configRegion = new ConfigRegion();
        byte[] user = UcenterUserUtils.getUser(session);
        DecimalFormat df = new DecimalFormat("######0.00");

        ucenterUser = (UcenterUser) ByteUtils.ByteToObject(user); if(null==ucenterUser){
            model.addAttribute("data","您的操作属于非法操作，所查看商品或设计师非您账户，请核实。");
            return  thymeleaf("/404");
        }
        byte[] address = UcenterUserUtils.getAddress(ucenterUser.getId());
        configRegion = (ConfigRegion) ByteUtils.ByteToObject(address);
        MaterialGoodsExample materialGoodsExample = new MaterialGoodsExample();
        materialGoodsExample.createCriteria().andCityIdEqualTo(configRegion.getRegionNumber().intValue()).andTypeSmallIdEqualTo(id).andStatusEqualTo(0);
        materialGoodsExample.setOrderByClause("sales desc");

        List<MaterialGoods> list =apiService.selectByPrimaryCity(materialGoodsExample,offset,limit);
        long total = apiService.countByCityExample(materialGoodsExample);
        List<MaterialGoodsModel> models= new ArrayList<>();
        for(MaterialGoods materialGoods:list){
            com.github.wenhao.geohash.GeoHash geoHash = com.github.wenhao.geohash.GeoHash.fromLong(materialGoods.getGeoCode());
            double distance = geoHash.distance(lat, lng);
            double distanceKm = distance / 1000;
            materialGoods.setDistanceKm(Double.valueOf(df.format(distanceKm)));
            MaterialGoodsModelExample materialGoodsModelExample  = new MaterialGoodsModelExample();
            materialGoodsModelExample.createCriteria().andGoodsIdEqualTo(materialGoods.getGoodsId());
            models = apiService.selectByMaterialGoodsModel(materialGoodsModelExample);
            Collections.sort(models);
            if(0!=models.size()){
                MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
                System.out.println(materialGoodsModel.getPrice());
                materialGoods.setModel(models.get(0));
            }else {
                MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
                materialGoodsModel.setPrice(0.00);
                materialGoodsModel.setGoodsId(materialGoods.getGoodsId());
                materialGoodsModel.setImgUrl("1221");
                materialGoods.setModel(materialGoodsModel);
            }

        }
        long tiao=limit-offset;
        double yeshu=(double)total/tiao;
        int ye = (int)Math.ceil(yeshu);
        Map map = new HashMap();
        map.put("smallId",id);
        map.put("ye",ye);
        map.put("total",total);
        map.put("limit",limit);
        map.put("offset",offset);
        map.put("result",list);
        return new WxplatformResult(WxplatformResultConstant.SUCCESS, map);
    }
    @RequestMapping(value = "/getGoods", method = RequestMethod.POST)
    private String getGoods(Model model, HttpServletRequest request, int id, @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                            @RequestParam(required = false, defaultValue = "4", value = "limit") int limit,
                            @RequestParam(required = false, value = "sort") String sort,
                            @RequestParam(required = false, value = "order") String order) {
        HttpSession session = request.getSession();
        UcenterUser ucenterUser = new UcenterUser();
        ConfigRegion configRegion = new ConfigRegion();
        byte[] user = UcenterUserUtils.getUser(session);
        ucenterUser = (UcenterUser) ByteUtils.ByteToObject(user); if(null==ucenterUser){
            model.addAttribute("data","您的操作属于非法操作，所查看商品或设计师非您账户，请核实。");
            return  thymeleaf("/404");
        }
        byte[] address = UcenterUserUtils.getAddress(ucenterUser.getId());
        configRegion = (ConfigRegion) ByteUtils.ByteToObject(address);
        MaterialGoodsExample materialGoodsExample = new MaterialGoodsExample();
        materialGoodsExample.createCriteria().andCityIdEqualTo(configRegion.getRegionNumber().intValue()).andTypeSmallIdEqualTo(id).andStatusEqualTo(0);
        materialGoodsExample.setOrderByClause("sales desc");

        List<MaterialGoods> list =apiService.selectByPrimaryCity(materialGoodsExample,offset,limit);
        long total = apiService.countByCityExample(materialGoodsExample);
        long tiao=limit-offset;
        double yeshu=(double)total/tiao;
        int ye = (int)Math.ceil(yeshu);
        Map map = new HashMap();
        model.addAttribute("smallId",id);
        model.addAttribute("ye",ye);
        model.addAttribute("total",total);
        model.addAttribute("limit",limit);
        model.addAttribute("offset",offset);
        return thymeleaf("/YZ/YZ_BD_SearchXQ");
    }

    @RequestMapping(value = "/getdistanceGoods", method = RequestMethod.POST)
    @ResponseBody
    private Object getdistanceGoods(Model model, HttpServletRequest request, int id, @RequestParam(required = false, defaultValue = "0", value = "distanceType") int distanceType,@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                                    @RequestParam(required = false, defaultValue = "4", value = "limit") int limit,
                                    @RequestParam(required = false, value = "sort") String sort,
                                    @RequestParam(required = false, value = "order") String order) {
        DecimalFormat df = new DecimalFormat("######0.00");
        HttpSession session = request.getSession();
        UcenterUser ucenterUser = new UcenterUser();
        ConfigRegion configRegion = new ConfigRegion();
        byte[] user = UcenterUserUtils.getUser(session);

        ucenterUser = (UcenterUser) ByteUtils.ByteToObject(user);
        if (null == ucenterUser) {
            model.addAttribute("data", "您的操作属于非法操作，所查看商品或设计师非您账户，请核实。");
            return thymeleaf("/404");
        }
        byte[] address = UcenterUserUtils.getAddress(ucenterUser.getId());
        configRegion = (ConfigRegion) ByteUtils.ByteToObject(address);
        String dqaddress = RedisUtil.get("dangqianweizhi"+ucenterUser.getId());
        net.sf.json.JSONObject jsonobject = net.sf.json.JSONObject.fromObject(dqaddress);
        UcenterUserCity usercity= (UcenterUserCity) net.sf.json.JSONObject.toBean(jsonobject,UcenterUserCity.class);
        int distanceCount = 0;
// N, NE, E, SE, S, SW, W, NW
        if (distanceType == 0) {
            distanceCount = 2000;
        } else if (distanceType == 1) {
            distanceCount = 5000;

        } else if (distanceType == 2) {
            distanceCount = 10000;

        } else if (distanceType == 3) {
            distanceCount = 20000;

        } else if (distanceType == 4) {
            distanceCount = 50000;

        }
        String json = RedisUtil.get(ucenterUser.getId() + "addressLNG");
        List<MaterialGoods> listarray = JSONArray.parseArray(json, MaterialGoods.class);


        MaterialGoodsExample materialGoodsExample = new MaterialGoodsExample();
         List<MaterialGoods> list = new ArrayList<MaterialGoods>();
        list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
        System.out.println(list.size());
        if (list.isEmpty()) {
            if (distanceType == 1) {
                distanceType = 2;
                distanceCount = 10000;
                list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);

                if (list.isEmpty()) {
                    distanceType = 3;
                    distanceCount = 20000;
                    list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                    if (list.isEmpty()) {
                        distanceType = 4;
                        distanceCount = 50000;
                        list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);

                    }
                }else{
                    if (compare(list, listarray)) {
                        distanceCount = 5000;
                        list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                        if (compare(list, listarray)) {
                            distanceCount = 10000;
                            list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                            if (compare(list, listarray)) {
                                distanceCount = 20000;
                                list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                                if (compare(list, listarray)) {
                                    distanceCount = 50000;
                                    list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                                }
                            } else {

                            }
                        } else {


                        }
                    } else {

                    }
                }
            } else if (distanceType == 2) {
                distanceType = 3;
                distanceCount = 20000;
                list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);

                if (list.isEmpty()) {
                    distanceType = 4;
                    distanceCount = 50000;
                    list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);

                }else{
                    if (compare(list, listarray)) {
                        distanceCount = 20000;
                        list = selcetMaterialGoods(distanceCount,usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                        if (compare(list, listarray)) {
                            distanceCount = 50000;
                            list = selcetMaterialGoods(distanceCount,usercity.getLat(), usercity.getLng(),ucenterUser, id, configRegion);
                        }
                    } else {

                    }
                }
            } else if (distanceType == 3) {
                distanceType = 4;
                distanceCount = 50000;
                list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                if (compare(list, listarray)) {
                    distanceCount = 50000;
                    list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(),ucenterUser, id, configRegion);
                }
            } else if (distanceType == 4) {
                return new WxplatformResult(WxplatformResultConstant.FAILED, "没有更多内容");

            }
        } else {

            if (distanceType == 1) {
                if (compare(list, listarray)) {
                    distanceCount = 5000;
                    list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                    if (compare(list, listarray)) {
                        distanceCount = 10000;
                        list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                        if (compare(list, listarray)) {
                            distanceCount = 20000;
                            list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                            if (compare(list, listarray)) {
                                distanceCount = 50000;
                                list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                            }
                        } else {

                        }
                    } else {


                    }
                } else {

                }
            } else if (distanceType == 2) {
                if (compare(list, listarray)) {
                    distanceCount = 20000;
                    list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                    if (compare(list, listarray)) {
                        distanceCount = 50000;
                        list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                    }
                } else {

                }

            } else if (distanceType == 3) {

                    if (compare(list, listarray)) {
                        distanceCount = 50000;
                        list = selcetMaterialGoods(distanceCount, usercity.getLat(), usercity.getLng(), ucenterUser, id, configRegion);
                    }
            } else if (distanceType == 4) {

            }


        }


        List<MaterialGoodsModel> models = new ArrayList<>();
        List<MaterialGoods> removeList = new ArrayList<>();
        System.out.println(list.toString());
        for (MaterialGoods materialGoods : list) {

            com.github.wenhao.geohash.GeoHash geoHash = com.github.wenhao.geohash.GeoHash.fromLong(materialGoods.getGeoCode());
            double distance = geoHash.distance(usercity.getLat(), usercity.getLng());
            if (distance > distanceCount) {
                removeList.add(materialGoods);
            } else {
                double distanceKm = distance / 1000;
                materialGoods.setDistanceKm(Double.valueOf(df.format(distanceKm)));
                MaterialGoodsModelExample materialGoodsModelExample = new MaterialGoodsModelExample();
                materialGoodsModelExample.createCriteria().andGoodsIdEqualTo(materialGoods.getGoodsId());
                models = apiService.selectByMaterialGoodsModel(materialGoodsModelExample);
                Collections.sort(models);
                if (0 != models.size()) {
                    MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
                    materialGoods.setModel(models.get(0));
                } else {
                    MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
                    materialGoodsModel.setPrice(0.00);
                    materialGoodsModel.setGoodsId(materialGoods.getGoodsId());
                    materialGoodsModel.setImgUrl("1221");
                    materialGoods.setModel(materialGoodsModel);
                }
            }


        }
        list.removeAll(removeList);

        String json1 = JSONArray.toJSONString(list);
        RedisUtil.del_add(ucenterUser.getId() + "addressLNG", json1);
        Map map = new HashMap();
        map.put("smallId", id);
        map.put("distanceType", distanceType);
        map.put("list", list);
        return new WxplatformResult(WxplatformResultConstant.SUCCESS, map);


    }


    @RequestMapping(value = "/nextPage", method = RequestMethod.POST)
    @ResponseBody
    private Object nextPage(Model model, HttpServletRequest request, int id, @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                            @RequestParam(required = false, defaultValue = "4", value = "limit") int limit,
                            @RequestParam(required = false, value = "sort") String sort,
                            @RequestParam(required = false, value = "order") String order) {
        HttpSession session = request.getSession();
        UcenterUser ucenterUser = new UcenterUser();
        ConfigRegion configRegion = new ConfigRegion();
        byte[] user = UcenterUserUtils.getUser(session);
        ucenterUser = (UcenterUser) ByteUtils.ByteToObject(user);
        String dqaddress = RedisUtil.get("dangqianweizhi"+ucenterUser.getId());
        net.sf.json.JSONObject jsonobject = net.sf.json.JSONObject.fromObject(dqaddress);
        UcenterUserCity usercity= (UcenterUserCity) net.sf.json.JSONObject.toBean(jsonobject,UcenterUserCity.class);
        DecimalFormat df = new DecimalFormat("######0.00");

        if (null == ucenterUser) {
            model.addAttribute("data", "您的操作属于非法操作，所查看商品或设计师非您账户，请核实。");
            return thymeleaf("/404");
        }
        byte[] address = UcenterUserUtils.getAddress(ucenterUser.getId());
        configRegion = (ConfigRegion) ByteUtils.ByteToObject(address);
        MaterialGoodsExample materialGoodsExample = new MaterialGoodsExample();
        materialGoodsExample.createCriteria().andCityIdEqualTo(configRegion.getRegionNumber().intValue()).andTypeSmallIdEqualTo(id).andStatusEqualTo(0);
        materialGoodsExample.setOrderByClause("sales desc");
        List<MaterialGoods> list = apiService.selectByPrimaryCity(materialGoodsExample, offset, limit);
        long total = apiService.countByCityExample(materialGoodsExample);

        System.out.println(list.size());
        List<MaterialGoodsModel> models = new ArrayList<>();
        for (MaterialGoods materialGoods : list) {
            com.github.wenhao.geohash.GeoHash geoHash = com.github.wenhao.geohash.GeoHash.fromLong(materialGoods.getGeoCode());
            double distance = geoHash.distance(usercity.getLat(), usercity.getLat());
            double distanceKm = distance / 1000;
            materialGoods.setDistanceKm(Double.valueOf(df.format(distanceKm)));
            MaterialGoodsModelExample materialGoodsModelExample = new MaterialGoodsModelExample();
            materialGoodsModelExample.createCriteria().andGoodsIdEqualTo(materialGoods.getGoodsId());
            models = apiService.selectByMaterialGoodsModel(materialGoodsModelExample);
            Collections.sort(models);
            if (0 != models.size()) {
                MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
                System.out.println(materialGoodsModel.getPrice());
                materialGoods.setModel(models.get(0));
            } else {
                MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
                materialGoodsModel.setPrice(0.00);
                materialGoodsModel.setGoodsId(materialGoods.getGoodsId());
                materialGoodsModel.setImgUrl("1221");
                materialGoods.setModel(materialGoodsModel);
            }

        }

        return new WxplatformResult(WxplatformResultConstant.SUCCESS, list);
    }

    @RequestMapping(value = "/shopXq")
    private String shopXq(Model model, HttpServletRequest request, int goodsId) throws Exception {
        MaterialGoodsExample materialGoodsExample = new MaterialGoodsExample();
        materialGoodsExample.createCriteria().andGoodsIdEqualTo(goodsId);
        MaterialGoods materialGoods = apiService.selectByGoods(materialGoodsExample);
        MaterialGoodsModelExample example = new MaterialGoodsModelExample();
        example.createCriteria().andGoodsIdEqualTo(materialGoods.getGoodsId());
        MaterialGoodsTypeSmallExample materialGoodsTypeSmallExample = new MaterialGoodsTypeSmallExample();
        materialGoodsTypeSmallExample.createCriteria().andSmallIdEqualTo(materialGoods.getTypeSmallId());
        materialGoods.setMaterialGoodsTypeSmall(apiService.selectSmall(materialGoodsTypeSmallExample));
        List<MaterialGoodsModel> models = apiService.selectByMaterialGoodsModel(example);

        if (0 != models.size()) {
            Collections.sort(models);
            MaterialGoodsModel materialGoodsModel = new MaterialGoodsModel();
            System.out.println(materialGoodsModel.getPrice());
            materialGoodsModel = models.get(0);
            materialGoods.setModelList(models);
            model.addAttribute("materialGoodsModel", materialGoodsModel);
            model.addAttribute("data", materialGoods);
            return thymeleaf("/YZ/YZ_SP_GoodsXQ");
        } else {

            model.addAttribute("data", materialGoods);
            return thymeleaf("/YZ/YZ_SP_GoodsXQ");
        }

    }

    private List<MaterialGoods> selcetMaterialGoods(int dict, double lat, double lng, UcenterUser ucenterUser, int id, ConfigRegion configRegion) {
        System.out.println(dict);
        long min0 = 0;//最小点
        long max0 = 0;//最大点
        long min1 = 0;//最小点
        long max1 = 0;//最大点
        long min2 = 0;//最小点
        long max2 = 0;//最大点
        long min3 = 0;//最小点
        long max3 = 0;//最大点
        long min4 = 0;//最小点
        long max4 = 0;//最大点
        long min5 = 0;//最小点
        long max5 = 0;//最大点
        long min6 = 0;//最小点
        long max6 = 0;//最大点
        long min7 = 0;//最小点
        long max7 = 0;//最大点        double min6;//最小点
        long min8 = 0;//最大点        double min6;//最小点
        long max8 = 0;//最大点
        List<GeoRange> geoRanges = GeoSearch.range(lat, lng, dict);
        for (int i = 0; i < geoRanges.size(); i++) {
            switch (i) {
                case 0:
                    min0 = geoRanges.get(i).getMin();
                    max0 = geoRanges.get(i).getMax();
                case 1:
                    min1 = geoRanges.get(i).getMin();
                    max1 = geoRanges.get(i).getMax();
                case 2:
                    min2 = geoRanges.get(i).getMin();
                    max2 = geoRanges.get(i).getMax();
                case 3:
                    min3 = geoRanges.get(i).getMin();
                    max3 = geoRanges.get(i).getMax();
                case 4:
                    min4 = geoRanges.get(i).getMin();
                    max4 = geoRanges.get(i).getMax();
                case 5:
                    min5 = geoRanges.get(i).getMin();
                    max5 = geoRanges.get(i).getMax();
                case 6:
                    min6 = geoRanges.get(i).getMin();
                    max6 = geoRanges.get(i).getMax();
                case 7:
                    min7 = geoRanges.get(i).getMin();
                    max7 = geoRanges.get(i).getMax();
                case 8:
                    min8 = geoRanges.get(i).getMin();
                    max8 = geoRanges.get(i).getMax();
            }
        }
        return apiService.selectByPrimaryDistance(configRegion.getRegionNumber().intValue(), id, 0, min0, max0, min1, max1, min2, max2, min3, max3, min4, max4, min5, max5, min6, max6, min7, max7, min8, max8);


    }

    /**
     * 队列比较
     *
     * @param <T>
     * @param a
     * @param b
     * @return
     */
    public static <T extends Comparable<T>> boolean compare(List<T> a, List<T> b) {
        if (a.size() != b.size())
            return false;
        Collections.sort(a);
        Collections.sort(b);
        for (int i = 0; i < a.size(); i++) {
            if (!a.get(i).equals(b.get(i)))
                return false;
        }
        return true;
    }

}
